package com.keyue.controller;

import com.keyue.common.annotation.AnonymousAccess;
import com.keyue.common.constant.ServerResult;
import com.keyue.service.LocalStorageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 *
 */
@RestController
@Api(tags = "文件上传")
@RequestMapping("/keyue/admin/api/localStorage")
public class LocalStorageController {

    @Resource
    private LocalStorageService localStorageService;

    @ApiOperation("上传文件")
    @PostMapping(value = "/upload")
    @AnonymousAccess
    public ServerResult upload(@RequestParam String name, @RequestParam("file") MultipartFile file) {
        return localStorageService.create(name, file);
    }

    @ApiOperation("上传图片到oss服务")
    @PostMapping(value = "/upload_oss")
    @AnonymousAccess
    public ServerResult upload2oss(@RequestParam String name, @RequestParam("file") MultipartFile file) {
        return localStorageService.uploadByAliOss(name, file);
    }

    @ApiOperation("上传图片到minio服务")
    @PostMapping(value = "/upload_minio")
    @AnonymousAccess
    public ServerResult upload2minio(@RequestParam String name, @RequestParam("file") MultipartFile file) {
        return localStorageService.uploadByMinIO(name, file);
    }

    @ApiOperation("上传文件到oss服务")
    @PostMapping(value = "/upload_file_oss")
    @AnonymousAccess
    public ServerResult uploadFile2oss(@RequestParam String name, @RequestParam("file") MultipartFile file) {
        return localStorageService.uploadFileByAliOss(name, file);
    }

    @ApiOperation("上传文件到oss服务")
    @PostMapping(value = "/upload_oss_v1")
    @AnonymousAccess
    public ServerResult upload2ossV2(@RequestParam String name, @RequestParam("file") MultipartFile file) {
        return localStorageService.uploadByAliOssV2(name, file);
    }

    @ApiOperation("上传文件到oss服务")
    @PostMapping(value = "/get_url_2_oss")
    @AnonymousAccess
    public ServerResult getUrl2ossV2(@RequestParam String name) {
        return localStorageService.getUrl2ossV2(name);
    }

}